﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Panny.Data;
using System.ComponentModel;
namespace Model
{
    [DataObject()]
   public class InformationData
   {
       #region insert
       [DataObjectMethod(DataObjectMethodType.Insert)]
       public int Insert(string infoType,string areaID,string source,string body,string corpTypeID,string title)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(" INSERT INTO Informations(InfoType,AreaID,Source,Body,CorpTypeID,Title) ");
           sql.Append(" values(@InfoType,@AreaID,@Source,@Body,@CorpTypeID,@Title) ");
           using (SqlText insertion = new SqlText(sql.ToString()))
           {
               insertion.AddParameter("@InfoType", infoType);
               insertion.AddParameter("@AreaID", areaID);
               insertion.AddParameter("@Source", source);
               insertion.AddParameter("@Body", body);
               insertion.AddParameter("@CorpTypeID", corpTypeID);
               insertion.AddParameter("@Title", title);
               return insertion.ExecuteNonQuery();
           }
       }
       #endregion
       [DataObjectMethod(DataObjectMethodType.Update)]
       public int Update(string infoType, string areaID, string source, string body, string corpTypeID, string title,string InfoID)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(" update Informations set InfoType =@InfoType,AreaID=@AreaID,Source=@Source,Body=@Body,CorpTypeID=@CorpTypeID,Title=@Title where InfoID= @InfoID ");
           using (SqlText updateion = new SqlText(sql.ToString()))
           {
               updateion.AddParameter("@InfoType", infoType);
               updateion.AddParameter("@AreaID", areaID);
               updateion.AddParameter("@Source", source);
               updateion.AddParameter("@Body", body);
               updateion.AddParameter("@CorpTypeID", corpTypeID);
               updateion.AddParameter("@Title", title);
               updateion.AddParameter("@InfoID", InfoID);
               return updateion.ExecuteNonQuery();
           }
       }
       #region update

       #endregion
       #region select
       [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet SelectSingle(int infoID)
       {
           string sql = @"SELECT [InfoID], [InfoType], [source], [ImageUrl], [Body], [Title], 
                        Informations.[CorpTypeID],c.TypeName as CorpTypeName,
                         a.[AreaID], a.AreaName, [InfoDate], [Hits]
                        FROM [Informations] left join Sys_Area a on a.AreaID = Informations.AreaID
                        left join CorpType c on informations.CorpTypeID = c.TypeID
                        WHERE InfoID = @InfoID";
           using (SqlText selection = new SqlText(sql))
           {
               selection.AddParameter("@InfoID", infoID);
               return selection.GetDataset();
           }
       }
       #endregion
   }
}
